cd E:\work\feizi\data



******************data processing*****************
use sibling,clear
gen sequence=elder_brother+elder_sister
gen eldest_child=0
replace eldest_child=1 if sequence==0
gen l_sequence=young_brother+young_sister
gen youngest_child=0
replace youngest_child=1 if l_sequence==0
gen only_child=0
replace only_child=1 if sib==0
label var period "After the reform and opening up"
label var year_edu "Educational years"
label var sib "The number of sibling"
label var han "Han nationality"
label var gender "Gender"  
label var urban_father "Household type of father"
label var  job_father "Father works in the public institution"
label var job_mother "Mother works in the public institution"
label var party_father "Father is a part member"
label var party_mother "Mother is a party member"
label var edu_father "The education level of father"
label var edu_mother "The education level of mother"
label var level_edu "Degree level of education"
label var total_income "Total income of family"
label var sequence "Children sequence"
label var only_child "The only child"
label var eldest_child "The eldest child"
label var youngest_child "The youngest child"
label var non_father "Fatherless child(14 years old)"
label var non_mother "Motherless child(14 years old)"
keep year_edu sib period han gender  urban_father  job_father job_mother party_father ///
party_mother edu_father edu_mother non_father non_mother level_edu total_income province countyid sequence only_child eldest_child youngest_child
des

********statistical description*********

sum year_edu sib period han gender  urban_father  job_father job_mother party_father ///
party_mother edu_father edu_mother non_father non_mothe level_edu total_income sequence only_child eldest_child youngest_child


tabulate  period
tabulate han
tabulate gender
tabulate urban_father
tabulate job_father
tabulate job_mother
tabulate party_father
tabulate party_mother
tabulate non_father
tabulate  non_mothe
tabulate only_child
tabulate  eldest_child
tabulate youngest_child




pwcorr_a year_edu level_edu sib han gender  urban_father   ///
edu_father edu_mother non_father non_mother ///
,star1(0.1) star5(0.05) star10(0.01)

collin sib han gender  urban_father edu_father job_father job_mother party_father party_mother 


/*hypothesis 1*/
reg year_edu sib 
est store reg1
reg year_edu sib han gender  urban_father edu_father job_mother party_father party_mother non_father
est store reg2
reg year_edu sib han gender  urban_father  edu_father  job_father party_father party_mother non_mother
est store reg3
reg year_edu sib han gender  urban_father  edu_fathe job_father job_mother party_father party_mother
est store reg4
tobit year_edu sib han gender  urban_father  edu_fathe job_father job_mother party_father party_mother,ll(1) ul(24)
est store reg5
ivreg year_edu (sib=party_mother  edu_mother) han gender  urban_father  edu_father job_father job_mother party_father ,first
est store reg6
overid
ivendog

esttab reg1 reg2 reg3 reg4 reg5 reg6, cells(b(star fmt(4)) se(par fmt(2))) /// 
label varwidth(40) varlabels(_cons Constant) mtitles("OLS" "OLS" "OLS" "OLS" "Tobit" "IV") /// 
stats(N r2, fmt(0 3) label(Observation R-square)) star(* 0.1 ** 0.05 *** 0.01)

pwcorr_a  sib party_mother  edu_mother ,star1(0.1) star5(0.05) star10(0.01)


/*hypothesis2*/   
reg year_edu sequence han gender  urban_father  edu_father  job_father job_mother party_father party_mother 
est store reg1
reg year_edu eldest_child han gender  urban_father  edu_father  job_father job_mother party_father party_mother 
est store reg2
reg year_edu youngest_child han gender  urban_father  edu_father  job_father job_mother party_father party_mother 
est store reg3
reg year_edu eldest_child youngest_child han gender  urban_father  edu_father  job_father job_mother party_father party_mother 
est store reg5
reg year_edu only_child han gender  urban_father  edu_father  job_father job_mother party_father party_mother 
est store reg4
esttab reg4 reg1 reg2 reg3 reg5, cells(b(star fmt(4)) se(par fmt(2))) /// 
label varwidth(40) varlabels(_cons Constant) mtitles("OLS" "OLS" "OLS" "OLS") /// 
stats(N r2, fmt(0 3) label(Observation R-square)) star(* 0.1 ** 0.05 *** 0.01)




reg sib gender han urban_father  edu_father    job_father job_mother party_father  party_mother 
predict a
reg year_edu sib a       
est store reg1
esttab reg1, cells(b(star fmt(4)) se(par fmt(2))) /// 
label varwidth(40) varlabels(_cons Constant) mtitles("OLS" "OLS" "OLS" "OLS") /// 
stats(N r2, fmt(0 3) label(Observation R-square)) star(* 0.1 ** 0.05 *** 0.01)

/*gender*/
gen female=0
replace female=1 if gender==0
gen sib_gender=gender*sib
gen eldest_female=eldest_child*female
gen eldest_gender1=eldest_child*female*sib
preserve
keep if gender==0
reg year_edu sib han urban_father edu_father job_father job_mother party_father party_mother 
est store reg1
esttab reg1, cells(b(star fmt(4)) se(par fmt(2))) /// 
varwidth(25) varlabels(_cons Constant) mtitles( "(1)") /// 
stats(N r2, fmt(0 3) label(Observation R-square)) star(* 0.1 ** 0.05 *** 0.01) 
restore
preserve
keep if gender==1
reg year_edu sib han urban_father edu_father job_father job_mother party_father party_mother 
est store reg1
esttab reg1, cells(b(star fmt(4)) se(par fmt(2))) /// 
varwidth(25) varlabels(_cons Constant) mtitles( "(2)") /// 
stats(N r2, fmt(0 3) label(Observation R-square))   star(* 0.1 ** 0.05 *** 0.01)
restore

reg year_edu sib sib_gender han gender  urban_father edu_father job_father job_mother party_father party_mother 
est store reg6
reg year_edu sib sib_gender eldest_gender1   gender han urban_father edu_father job_father job_mother party_father party_mother
est store reg5
esttab reg6 reg5, cells(b(star fmt(4)) se(par fmt(2))) /// 
varwidth(25) varlabels(_cons Constant) mtitles("3") /// 
stats(N r2, fmt(0 3) label(Observation R-square)) star(* 0.1 ** 0.05 *** 0.01)



/*urban*/
gen rural=0
replace rural=1 if urban_father==0
replace rural=. if urban_father==.
gen sib_urban=sib*rural
gen sib_urban_female=sib*rural*female
preserve
keep if urban_father==0
reg year_edu sib han gender edu_father job_father job_mother party_father party_mother 
est store reg1
esttab reg1, cells(b(star fmt(4)) se(par fmt(2))) /// 
varwidth(25) varlabels(_cons Constant) mtitles( "(1)") /// 
stats(N r2, fmt(0 3) label(Observation R-square))  star(* 0.1 ** 0.05 *** 0.01)
restore
preserve
keep if urban_father==1
reg year_edu sib han gender edu_father job_father job_mother party_father party_mother 
est store reg1
esttab reg1, cells(b(star fmt(4)) se(par fmt(2))) /// 
varwidth(25) varlabels(_cons Constant) mtitles( "(2)") /// 
stats(N r2, fmt(0 3) label(Observation R-square)) star(* 0.1 ** 0.05 *** 0.01)
restore
diff year_edu,t(sib) p(urban_father) cov(han gender edu_father  job_father job_mother party_father party_mother)
est store diff
reg year_edu sib sib_urban female rural han edu_father job_father job_mother party_father party_mother 
est store reg5
reg year_edu sib sib_urban sib_urban_female  female rural han   edu_father job_father job_mother party_father party_mother 
est store reg6
esttab reg5 reg6, cells(b(star fmt(4)) se(par fmt(2))) /// 
 varwidth(25) varlabels(_cons Constant) mtitles("3") /// 
stats(N r2, fmt(0 3) label(Observation R-square)) star(* 0.1 ** 0.05 *** 0.01)


/*period*/
preserve
keep if period==0
reg year_edu sib han gender urban_father edu_father job_father job_mother party_father party_mother 
est store reg1
esttab reg1, cells(b(star fmt(4)) se(par fmt(2))) /// 
varwidth(25) varlabels(_cons Constant) mtitles( "(1)") /// 
stats(N r2, fmt(0 3) label(Observation R-square))  star(* 0.1 ** 0.05 *** 0.01)
restore
preserve
keep if period==1
reg year_edu sib han gender urban_father edu_father job_father job_mother party_father party_mother 
est store reg1
esttab reg1, cells(b(star fmt(4)) se(par fmt(2))) /// 
varwidth(25) varlabels(_cons Constant) mtitles( "(2)") /// 
stats(N r2, fmt(0 3) label(Observation R-square))   star(* 0.1 ** 0.05 *** 0.01)
restore
diff year_edu,t(sib) p(period) cov(han gender urban_father edu_father job_father job_mother party_father party_mother)
est store reg1
diff year_edu,t(sib_gender) p(period) cov(sib han gender urban_father edu_father job_father job_mother party_father party_mother)
est store reg2
diff year_edu,t(sib_urban) p(period) cov(sib han gender urban_father edu_father job_father job_mother party_father party_mother)
est store reg3
esttab reg1 reg2 , cells(b(star fmt(4)) se(par fmt(2))) /// 
varwidth(25) varlabels(_cons Constant) mtitles( "(2)") /// 
stats(N r2, fmt(0 3) label(Observation R-square)) star(* 0.1 ** 0.05 *** 0.01)


***********robust test******


/*替代*/
reg level_edu sib 
est store reg1
reg level_edu sib han gender  urban_father edu_father job_mother party_father party_mother non_father
est store reg2
reg level_edu sib han gender  urban_father  edu_father  job_father party_father party_mother non_mother
est store reg3
reg level_edu sib han gender  urban_father  edu_fathe job_father job_mother party_father party_mother
est store reg4
tobit level_edu sib han gender  urban_father  edu_fathe job_father job_mother party_father party_mother,ll(0) ul(6)
est store reg5
esttab reg1 reg2 reg3 reg4 reg5, cells(b(star fmt(4)) se(par fmt(2))) /// 
label varwidth(40) varlabels(_cons Constant) mtitles("OLS" "OLS" "OLS" "OLS" "Tobit" ) /// 
stats(N r2, fmt(0 3) label(Observation R-square)) star(* 0.1 ** 0.05 *** 0.01)


